
var express = require('express');
var jwt = require('jwt-simple');
var app = express();
app.set('jwtTokenSecret', 'YOUR_SECRET_STRING');
var moment = require('moment');
var router = express.Router();

var sql = require('../sql.js');
router.use('/', function(req, res) {
  /*res.send('1');*/
  var params = req.query;  
  console.log(params.userName)
  console.log(params)
  sql(`select admin.id,admin.userName,admin.pwd,admin.cover,admin.photo from admin`, function(qerr,vals,fields){  
    //do something   
        if(qerr){
            data = {state: 0, vals: '服务器出现问题，请稍等'};
            throw qerr
        };      
          if(vals.length==0){
              data = {state: 0, vals: '请输入信息'};   
            } 
            else {
                /**设置移动端登录连续七天过后过期**/
                var expires = moment().add(7, 'days').valueOf();
                var token = jwt.encode({
                  iss: vals.id,
                  exp: expires,
                },app.get('jwtTokenSecret'));    
                data = {state: 1, vals: vals, token: token};   
                                
        }
        return res.json(data)
});  
});
module.exports = router;
